﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>控制两个文本框只输其一</title>
    <script type="text/javascript" language="JavaScript">
        function checkFields(){
            name = document.submitform.name.value;  // 获取姓名
            email = document.submitform.email.value;    // 获取邮箱
            if((name === "") && (email === "")){
                // 如果两者都为空
                alert('请输入姓名和邮箱！');
                return false;
            }else{
                return true;
            }
        }

    </script>
</head>
<body>

<form  name=submitform onSubmit="return checkFields()">
    名字和邮箱只需要输入一个即可<br>
    <br>
    <table border=0>
        <tr>
            <td align=center>名字</td><td> </td>
            <td align=center>Email</td></tr><tr>
        <td align=center><input type=text name=name value="" onFocus="document.submitform.email.value='';" size=10></td>
        <td align=center>或</td>
        <td align=center><input type=text name=email value="" onFocus="document.submitform.name.value='';" size=10></td>
    </tr>
        <tr>
            <td colspan=3 align=center><input type=submit value="提交"></td>
        </tr>
    </table>
</form>

</body>
</html>